package com.java.basis.thread.n3.shunxu;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @author wangning
 * @create 2022-01-24 16:28
 */
@Slf4j(topic = "c.Test03")
public class Test03 {
	private static ReentrantLock lock = new ReentrantLock();
	//表示t2是否运行过
	static boolean t2Runned = false;

	public static void main(String[] args) {
		Condition condition1 = lock.newCondition();
		Thread t1 = new Thread(() -> {
			lock.lock();
			while (!t2Runned) {
				try {
					condition1.await();
				} catch (InterruptedException e) {
					e.printStackTrace();
				}

			}
			log.debug("1");



		});
		Thread t2 = new Thread(() -> {
			lock.lock();
			try {
				t2Runned = true;
				log.debug("2");
				condition1.signalAll();
			} finally {
				lock.unlock();

			}
		});

		t1.start();
		t2.start();

	}

}
